import time


def timer(func):
    """
    计时装饰器
    A decorator that prints the time it takes to execute a function.
    :param func:需要装饰的函数
    :return:函数结果
    """
    def wrapper(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        print(f"{func.__name__} took {end_time - start_time:.2f} seconds to execute.")
        return result

    return wrapper
